package main

import "fmt"
func main(){
	// 测试用例
	fmt.Println(Jaccard([]int{1,1,3,4,5}, []int{1,2,3,4,5}))

}


//func Jaccard[T Comparable](collection1, collection2 []T)float64{
func Jaccard(collection1, collection2 []int)float64{
	if len(collection1) == 0 || len(collection2) == 0 {
		return 0
	}

	map1 := make(map[int]struct{},len(collection1))
	for _, v := range collection1 {
		map1[v] = struct{}{}
	}
	map2 := make(map[int]struct{},len(collection2))
	for _, v := range collection2 {
		map2[v] = struct{}{}
	}
	intersection := 0
	for key := range map1 {
		if _, ok := map2[key]; ok {
			intersection++
		}
	}
	return float64(intersection) / float64(len(map1)+len(map2)-intersection)
}